package com.huan;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;


//调用连接类
public class Call {

    //创建上下文对象
    public static Configuration conf ;
    //创建Hbase连接池
    public static Connection conn = null;
    //创建 管理员
    public static Admin admin = null;


    //静态代码块,优先执行
    static {
        try {
            //创建上下文对象并连接hbase属性
            conf = HBaseConfiguration.create();
            conf.set( "hbase.zookeeper.quorum","Bigdata01,Bigdata02,Bigdata03" );
            //连接池调用工厂连接类
            conn = ConnectionFactory.createConnection( conf );
            //用连接池获取hbase的管理员
            admin = conn.getAdmin();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void close(){
        try {
            //如果管理员不等于空则关闭资源
            if(admin != null) {
                admin.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            //如果连接不等于空则关闭连接
            if(conn != null){
                conn.close();
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }

}
